function* OrderAggregate() {
	try {
		while (true) {
			const action = yield take('PlaceOrder')
				//do something ...
			yield put({
				type: "OrderCreated",
				payload
			});
			yield take('OrderConfirmed')
				//do something ...
		}
	} catch (e) {
		yield put({
			type: "OrderError",
			message: e.message
		});
	}

}

function* ReservationAggregate() {
	try {
		while (true) {
			const action = yield take('MakeReservation')
				//do fetch...
			const {
				data
			} = yield call(ServerUrl, {
				...param
			});
			if (data.success) {
				yield put({
					type: "SeatReserved",
					payload
				});
			} else {
				yield put({
					type: "SeatNotReserved",
					payload
				});
			}
			yield take('OrderConfirmed')
				//do something ...
		}
	} catch (e) {
		yield put({
			type: "ReservedError",
			message: e.message
		});
	}
}

function* PayMentAggregate(action) {
	try {
		while (true) {
			const action = yield take('MakePayment')
				//do something ...
			yield put({
				type: "PaymentAccepted",
				payload
			});
			yield take('OrderConfirmed')
				//do something ...
		}
	} catch (e) {
		yield put({
			type: "PayMentError",
			message: e.message
		});
	}
}

function* WaitListAggregate(action) {
	try {
		while (true) {
			const action = yield take('AddSeatsToWaitList')
				//do something ...

		}
	} catch (e) {
		yield put({
			type: "WaitListError",
			message: e.message
		});
	}
}

function* OderProcessManager() {

	try {
		while (true) {

			const order = yield take('OrderCreated')
			yield put({
				type: "MakeReservation",
				order
			});
			const action = yield take(['SeatReserved', 'SeatNotReserved'])
			if (action.type == "SeatReserved") {
				yield take('PaymentAccepted')
			} else {
				yield put({
					type: "AddSeatsToWaitList",
					action
				});
			}
			yield put({
				type: "OrderConfirmed",
				action
			});
		}
	} catch (e) {
		yield put({
			type: "OrderProcessError",
			message: e.message
		});
	}

}

function* Order() {
	try {
		while (true) {
			const task = yield fork(OderProcessManager, name, password, ...)
			const action = yield take(['OrderError', 'ReservationError', 'PaymentError'])
			yield cancel(action)
		}
	} catch (e) {
		yield put({
			type: "OrderError",
			message: e.message
		});
	} finally {
		if (yield cancelled()) {
			// ... put special cancellation handling code here
		}
	}
}